{extend name="layout/main-block" /}
<!-- main content start -->
{block name="content"}
<section id="main-content">
    <section class="wrapper">
        <div class="row">
            <ol class="breadcrumb">
                <li class="h4"><a href="">新建人员</a></li>
            </ol>
        </div>
        <div class="row content-main">
            <div class="col-sm-12 col-md-6">
                <form class="form-horizontal" action="{:url('backend/people/people_create')}" enctype="multipart/form-data" method="post">
                    <div class="form-group ">
                        <label class="col-sm-3 col-md-4 col-lg-3 control-label">导航菜单</label>
                        <div class="col-sm-9 col-md-8  col-lg-9">
                            <select name="nav-select" id="nav-select" class="form-control">
                                {volist name="team" id="v" empty="$empty" }
                                <option value="{$v.team_id}">{$v.team_name_cn}</option>
                                {/volist}
                            </select>
                        </div>
                    </div>
                    <div id="depart" class="form-group ">
                        <label class="col-sm-3 col-md-4 col-lg-3 control-label">部门</label>
                        <div class="col-sm-9 col-md-8  col-lg-9">
                            <select name="depart-select" id="depart-select" class="form-control">
                                {volist name="depart" id="v" empty="$empty" }
                                <option value="{$v.department_id}">{$v.department_name_cn}</option><!--新建处分配变量select出部门-->
                                {/volist}
                            </select>
                        </div>
                    </div>
                    <div id="people_cn" class="form-group">
                        <label for="inputName_cn" class="col-sm-3  col-md-4 col-lg-3 control-label">人员名称中文</label>
                        <div class="col-sm-9 col-md-8  col-lg-9">
                            <input type="text" name="name_cn" class="form-control" id="inputName_cn" placeholder="人员名称中文...">
                        </div>
                    </div>
                    <div id="people_en" class="form-group">
                        <label for="inputName_en" class="col-sm-3  col-md-4 col-lg-3 control-label">人员名称英文</label>
                        <div class="col-sm-9 col-md-8  col-lg-9">
                            <input type="text" name="name_en" class="form-control" id="inputName_en" placeholder="人员名称英文...">
                        </div>
                    </div>
                    <div id="img_s" class="form-group">
                        <label for="inputS_img_url" class="col-sm-3 col-md-4 col-lg-3 control-label">小图片</label>
                        <div class="col-sm-9 col-md-8  col-lg-9">
                            <input id="inputS_img_url" name="image[]" type="file"  value="浏览" >
                        </div>
                    </div>
                    <div id="img_b" class="form-group" style="display: block">
                        <label for="inputB_img_url" class="col-sm-3 col-md-4 col-lg-3 control-label">大图片</label>
                        <div class="col-sm-9 col-md-8  col-lg-9">
                            <input id="inputB_img_url" name="image[]" type="file"  value="浏览" >
                        </div>
                    </div>
                    <div id="dic_cn" class="form-group" style="display: none">
                        <label for="inputDictum_cn" class="col-sm-3  col-md-4 col-lg-3 control-label">格言中文</label>
                        <div class="col-sm-9 col-md-8  col-lg-9">
                            <input type="text" name="dictum_cn" class="form-control" id="inputDictum_cn" placeholder="格言中文...">
                        </div>
                    </div>
                    <div id="dic_en" class="form-group" style="display: none">
                        <label for="inputDictum_en" class="col-sm-3  col-md-4 col-lg-3 control-label">格言英文</label>
                        <div class="col-sm-9 col-md-8  col-lg-9">
                            <input type="text" name="dictum_en" class="form-control" id="inputDictum_en" placeholder="格言英文...">
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-sm-offset-3 col-sm-9">
                            <button type="submit" class="btn btn-primary">创 建</button>
                            <input type="hidden" id="img_type" name="img_type" value="0">
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </section>
</section>
{/block}

{block name="javascript"}
<script>
    $(function (){
        $('#nav-select').bind('change',function() {
            var team =$('#nav-select').val();
            //console.log(team);
            if(team ==1){
                $("#dic_cn").hide();
                $("#dic_en").hide();
                $("#img_b").show();
                $("#depart").show();
            }else if(team == 2){
                $("#dic_cn").show();
                $("#dic_en").show();
                $("#depart").hide();
                $("#img_b").show();
            }else if(team == 3){
                $("#dic_cn").hide();
                $("#dic_en").hide();
                $("#depart").hide();
                $("#img_b").hide();
            }
        });

        //图片上传
         var firstFlag = secondFlag = false;
         $('input[type=file]').each(function (index, ele) {
         // 判断 hidden 控件的值（两个文件上传控件index+1 后的和值）
         // 如果最后值是1，说明是上传的第一个文件
         // 如果最后值是2，说明是上传的第二个文件
         var index2 = index + 1;
         //console.log($('input#img_type').val());
         // 选择一个文件后触发此事件，表明一定是选择了文件
         $(this).change(function (e) {
         // 如果本次上传的是第一个文件，并且第一个文件控件之前点击后
         if(!(((index2 == 1) && firstFlag) || ((index2 == 2) && secondFlag)))
         {
         $('input#img_type').val(parseInt(parseInt($('input#img_type').val()) + index2));
         }

         if(index2 == 1)
         {
         firstFlag = true;
         } else if (index2 == 2){
         secondFlag = true;
         }
         //console.log($('input#img_type').val());
         });
         });
    })

</script>
{/block}

